package me.fangx.zhihu.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.RelativeLayout;

/**
 * 作者： Owen
 * 时间： 2016/6/1 0030 11:17
 * 类说明：自定义RelativeLayout组件基类
 */
public abstract class CustomBaseViewRelative extends RelativeLayout {

    public Context mContext;
    public LayoutInflater mInflater;

    protected abstract int getLayoutId();
    protected abstract void initView();

    public CustomBaseViewRelative(Context context) {
        super(context);
        this.mContext = context;
        this.mInflater = LayoutInflater.from(this.mContext);
        try {
            if (getLayoutId() != -1) {
                this.mInflater.inflate(getLayoutId(), this, true);
            }
            initView();
        } catch (OutOfMemoryError e) {
            e.printStackTrace();
        }
    }

    public CustomBaseViewRelative(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.mContext = context;
        this.mInflater = LayoutInflater.from(this.mContext);
        try {
            if (getLayoutId() != -1) {
                this.mInflater.inflate(getLayoutId(), this, true);
            }
            initView();
        } catch (OutOfMemoryError e) {
            e.printStackTrace();
        }
    }
}
